# vcc-reg/app.py 
# 
# This file is part of vcc-reg. 
# 
# vcc-reg is free software: you can redistribute it and/or modify 
# it under the terms of the GNU General Public License as published by 
# the Free Software Foundation, either version 3 of the License, or 
# (at your option) any later version. 
# 
# vcc-reg is distributed in the hope that it will be useful, 
# but WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
# GNU General Public License for more details. 
# 
# You should have received a copy of the GNU General Public License 
# along with vcc-reg. If not, see <https://www.gnu.org/licenses/>


from flask import Flask
from flask import render_template
from flask import request

from os import system
import config

app = Flask(__name__, template_folder="./templates");

@app.route("/")
def index():
    return render_template("index.html", host=config.hostname)

@app.route('/register', methods=["POST"])
def register():
    user = request.form.get("username").replace('\n', '')
    passwd = request.form.get("password").replace('\n', '')

    if system(config.adduser_path % (user, passwd)) != 0:
        return render_template("failure.html")

    return render_template("success.html", username=user, host=config.hostname)


if __name__ == '__main__':
    app.run(debug=False, port=config.port, host="0.0.0.0")

